package com.vlin.config.scene;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.vlin.scene.actuator.ListCommandHandler;
import com.vlin.scene.actuator.ListSceneResolver;
import com.vlin.scene.actuator.SceneActuator;
import com.vlin.scene.actuator.SceneResolver;
import com.vlin.scene.actuator.TimerExecutor;
import com.vlin.scene.actuator.defaut.DefaultListCommandHandler;
import com.vlin.scene.actuator.defaut.DefaultListSceneResolver;
import com.vlin.scene.actuator.defaut.DefaultSceneActuator;
import com.vlin.scene.actuator.defaut.DefaultSceneResolver;
import com.vlin.scene.actuator.defaut.DefaultTimerExecutor;
import com.vlin.scene.command.tuya.TuyaCommandHandler;
import com.vlin.scene.command.tuya.TuyaCommandProducer;
import com.vlin.service.tuya.TuyaService;

@Configuration
public class SceneConfig {
	
	@Autowired
	private TuyaService tuyaService;

	@Bean
	public ListSceneResolver listSceneResolver() {
		ListSceneResolver listResolver = new DefaultListSceneResolver();
		SceneResolver resolver = new DefaultSceneResolver();
		resolver.addCommandProducer(new TuyaCommandProducer());
		listResolver.addSceneResolver(resolver);
		return listResolver;
	}
	
	@Bean
	public TimerExecutor timerExecutor() {
		TimerExecutor timerExecutor = new DefaultTimerExecutor();
		ListCommandHandler commandHandler = new DefaultListCommandHandler();
		commandHandler.addCommandHandler(new TuyaCommandHandler(tuyaService));
		timerExecutor.setListCommandHandler(commandHandler);
		return timerExecutor;
	}
	
	@Bean
	public SceneActuator sceneActuator(ListSceneResolver listSceneResolver, TimerExecutor timerExecutor) {
		SceneActuator sceneActuator = new DefaultSceneActuator();
		sceneActuator.setSceneResolver(listSceneResolver);
		return sceneActuator;
	}

}
